using UnityEngine;
using UnityEngine.UI;

namespace HEFramework
{
    /// <summary>
    ///
    /// 画布自适应行为
    /// 
    /// ----------------------------------------
    /// 作者 hep
    /// 创建时间：2023-01-18 18:52:07
    /// ----------------------------------------
    /// </summary>
    public class CanvasScalerBehaviour : CanvasScaler
    {
        protected override void HandleScaleWithScreenSize()
        {
            //根据当前当前屏幕分辨率决定适配模式
            if (m_ReferenceResolution.x > m_ReferenceResolution.y)
            {
                //横屏
                if (Screen.width / m_ReferenceResolution.x < Screen.height / m_ReferenceResolution.y)
                {
                    matchWidthOrHeight = 0f;
                }
                else
                {
                    matchWidthOrHeight = 1f;
                }
            }
            else
            {
                //竖屏
                if (Screen.width / m_ReferenceResolution.x > Screen.height / m_ReferenceResolution.y)
                {
                    matchWidthOrHeight = 0f;
                }
                else
                {
                    matchWidthOrHeight = 1f;
                }
            }

            base.HandleScaleWithScreenSize();
        }
    }
}